import { faker } from '@faker-js/faker';
import {
  EventTypeEnum,
  MatchPlayerStatusEnum,
  MatchStatusEnum,
} from 'src/common/constant/enums';
import { MatchInfo } from 'src/modules/match/entities/match.entity';

export function generateMatchInfoMock(
  partialMatchInfo?: Partial<MatchInfo>,
): MatchInfo {
  const mockMatchInfo: MatchInfo = {
    id: partialMatchInfo?.id ?? faker.number.int(),
    groupLoopIndex:
      partialMatchInfo?.groupLoopIndex ?? faker.number.int({ min: 1, max: 10 }),
    type: partialMatchInfo?.type ?? faker.helpers.enumValue(EventTypeEnum),
    isTeamMatch: partialMatchInfo?.isTeamMatch ?? faker.datatype.boolean(),
    homePlayerId: partialMatchInfo?.homePlayerId ?? faker.number.int(),
    awayPlayerId: partialMatchInfo?.awayPlayerId ?? faker.number.int(),
    winnerId: partialMatchInfo?.winnerId ?? faker.number.int(),
    homePlayer: partialMatchInfo?.homePlayer,
    awayPlayer: partialMatchInfo?.awayPlayer,
    winner: partialMatchInfo?.winner,
    homePlayerRally:
      partialMatchInfo?.homePlayerRally ??
      faker.number.int({ min: 0, max: 100 }),
    awayPlayerRally:
      partialMatchInfo?.awayPlayerRally ??
      faker.number.int({ min: 0, max: 100 }),
    homePlayerStatus:
      partialMatchInfo?.homePlayerStatus ??
      faker.helpers.enumValue(MatchPlayerStatusEnum),
    awayPlayerStatus:
      partialMatchInfo?.awayPlayerStatus ??
      faker.helpers.enumValue(MatchPlayerStatusEnum),
    status:
      partialMatchInfo?.status ?? faker.helpers.enumValue(MatchStatusEnum),
    rangeMin: partialMatchInfo?.rangeMin ?? faker.number.int(),
    rangeMax: partialMatchInfo?.rangeMax ?? faker.number.int(),
    gameRule: partialMatchInfo?.gameRule,
    rallyRule: partialMatchInfo?.rallyRule,
    gameRuleId: partialMatchInfo?.gameRuleId ?? faker.number.int(),
    rallyRuleId: partialMatchInfo?.rallyRuleId ?? faker.number.int(),
    createBy: partialMatchInfo?.createBy ?? faker.number.int(),
    createTime: partialMatchInfo?.createTime ?? faker.date.past(),
    updateBy: partialMatchInfo?.updateBy ?? faker.number.int(),
    updateTime: partialMatchInfo?.updateTime ?? faker.date.recent(),
    estimatedStart: partialMatchInfo?.estimatedStart ?? faker.date.future(),
    estimatedEnd: partialMatchInfo?.estimatedEnd ?? faker.date.future(),
    actualStart: partialMatchInfo?.actualStart ?? faker.date.past(),
    actualEnd: partialMatchInfo?.actualEnd ?? faker.date.past(),
    groupMatchIndex:
      partialMatchInfo?.groupMatchIndex ??
      faker.number.int({ min: 1, max: 100 }),
    nextWinnerMatchIndex:
      partialMatchInfo?.nextWinnerMatchIndex ??
      faker.number.int({ min: 1, max: 100 }),
    nextLoserMatchIndex:
      partialMatchInfo?.nextLoserMatchIndex ??
      faker.number.int({ min: 1, max: 100 }),
    subMatchOrder:
      partialMatchInfo?.subMatchOrder ?? faker.number.int({ min: 1, max: 10 }),
    groupId: partialMatchInfo?.groupId ?? faker.number.int(),
    subMatchId: partialMatchInfo?.subMatchId ?? faker.number.int(),
    playground: partialMatchInfo?.playground,
    playgroundId: partialMatchInfo?.playgroundId ?? faker.number.int(),
    group: partialMatchInfo?.group,
    parentMatchInfo: partialMatchInfo?.parentMatchInfo,
    subMatchInfos: partialMatchInfo?.subMatchInfos,
    games: partialMatchInfo?.games,
    tournamentId: partialMatchInfo?.tournamentId ?? faker.number.int(),
    tournament: partialMatchInfo?.tournament,
    categoryId: partialMatchInfo?.categoryId ?? faker.number.int(),
    category: partialMatchInfo?.category,
    stageId: partialMatchInfo?.stageId ?? faker.number.int(),
    stage: partialMatchInfo?.stage,
    eventId: partialMatchInfo?.eventId ?? faker.number.int(),
    event: partialMatchInfo?.event,
    // eventPlayerId: partialMatchInfo?.eventPlayerId ?? faker.number.int(),
    // eventPlayer: partialMatchInfo?.eventPlayer,
    mustFinishMaxCountGame:
      partialMatchInfo?.mustFinishMaxCountGame ?? faker.datatype.boolean(),
    mustFinishMaxCountMatch:
      partialMatchInfo?.mustFinishMaxCountMatch ?? faker.datatype.boolean(),
    hasByePlayer: partialMatchInfo?.hasByePlayer ?? faker.datatype.boolean(),
    BeforeInsert: function (): void {
      throw new Error('Function not implemented.');
    },
    BeforeUpdate: function (): void {
      throw new Error('Function not implemented.');
    },
  };

  return mockMatchInfo;
}
